import java.util.Arrays;

/*
 * @lc app=leetcode.cn id=673 lang=java
 *
 * [673] 最长递增子序列的个数
 */

// @lc code=start
class Solution {
    public int findNumberOfLIS(int[] nums) {
        if(nums.length == 0 || nums == null){
            return 0;
        }
        int maxLen = 0;
        // 到nums[i]为止的最长递增子序列长度
        int[] dp = new int[nums.length];
        // 到nums[i]为止的最长递增子序列个数
        int[] count = new int[nums.length];
        for (int i = 0; i < count.length; i++) {
            dp[i] = 1;
            count[i] = 1;
        }
        for (int i = 1; i < count.length; i++) {
            for (int j = 0; j < i; j++) {
                if(nums[i] > nums[j]){
                    if (dp[j] + 1 == dp[i]) {
                        count[i] += count[j];
                    } else if (dp[j] + 1 > dp[i]){
                        count[i] = count[j];
                        dp[i] = dp[j] + 1;
                    }
                    
                }
            }
            maxLen = Math.max(maxLen, dp[i]);
        }
        int ans = 0;
        for (int i = 0; i < dp.length; i++) {
            if(dp[i] == maxLen){
                ans += count[i];
            }
        }
        System.out.println(Arrays.toString(dp));
        System.out.println(Arrays.toString(count));
        return ans;
    }
}
// @lc code=end

